#include "episode.h"

Episode::Episode()
{
    this->id = 0;
    this->numero = 0;
    this->taille = "0Mo";
    this->hits = 0;
    this->codec = "None";
    this->resolution = "0x0";
    this->duree = "0";
    this->nom = "None";
}

Episode::Episode(Episode *episode){

    this->id = episode->id;
    this->numero = episode->numero;
    this->taille = episode->taille;
    this->hits = episode->hits;
    this->codec = episode->codec;
    this->resolution = episode->resolution;
    this->duree = episode->duree;
    this->nom = episode->nom;
}

void Episode::load(QDomNode* node) {
    QDomNodeList children = node->childNodes();
    qDebug() << children.count();
    QStringList myOptions;
    myOptions << "id" << "nom" << "num" << "codec" << "resolution" << "duree" << "taille" << "dateajout" << "hits";

    int i;
    for(i=0; i<children.count(); i++) {
        switch(myOptions.indexOf(children.item(i).nodeName())) {
            case 0:
            //id
            this->setId(children.item(i).toElement().text().toInt());
            break;
            case 1:
            //nom
            this->setNom(children.item(i).toElement().text());
            break;
            case 2:
            //num
            this->setNumero(children.item(i).toElement().text().toInt());
            break;
            case 3:
            //codec
            this->setCodec(children.item(i).toElement().text());
            break;
            case 4:
            //resolution
            this->setResolution(children.item(i).toElement().text());
            //qDebug() << children.item(i).toElement().text();
            break;
            case 5:
            //duree
            this->setDuree(children.item(i).toElement().text());
            break;
            case 6:
            //taille
            this->setTaille(children.item(i).toElement().text());
            break;
            case 7:
            //dateajout
            // TODO : NOT IMPLEMENTED YET
            break;
            case 8:
            //hits
            this->setHits(children.item(i).toElement().text().split(" ").at(0).toInt());
            break;
        }
    }
    if(this->getNom() == "None")
        this->formatName();
}

void Episode::formatName(){
    QString nom = QString("%1 - ").arg(this->numero);
    nom += this->codec;
    nom += " (";
    nom += this->resolution;
    nom += "), ";
    nom += this->taille + " - " + this->duree;

    this->setNom(nom);

}

int Episode::getId(){
    return this->id;
}
int Episode::getNumero(){
    return this->numero;
}
int Episode::getHits(){
    return this->hits;
}
QString& Episode::getTaille(){
    return this->taille;
}
QString& Episode::getCodec(){
    return this->codec;
}
QString& Episode::getResolution(){
    return this->resolution;
}
QString& Episode::getDuree(){
    return this->duree;
}
QString& Episode::getNom(){
    return this->nom;
}

void Episode::setId(int id){
    this->id = id;
}
void Episode::setNumero(int numero){
    this->numero = numero;
}
void Episode::setHits(int hits){
    this->hits = hits;
}
void Episode::setTaille(const QString& taille){
    this->taille = taille;
}
void Episode::setCodec(const QString& codec){
    this->codec = codec;
}
void Episode::setResolution(const QString& resolution){
    this->resolution = resolution;
}
void Episode::setDuree(const QString& duree){
    this->duree = duree;
}
void Episode::setNom(const QString& nom){
    this->nom = nom;
    this->setText(this->nom);
}

